package com.microframework.base.data.enums;

import java.util.Arrays;
import java.util.Optional;

/**
 * 数据源类型枚举 + 实体
 * 既可作为枚举使用，又可持久化到数据库
 */
public enum SourceType {
    
    HTTP("http", "HTTP接口", "通过HTTP/HTTPS协议访问的RESTful或SOAP接口", "http-icon"),
    MQTT("mqtt", "MQTT协议", "基于发布/订阅模式的物联网消息协议", "mqtt-icon"),
    WEBSOCKET("websocket", "WebSocket", "全双工通信协议", "websocket-icon"),
    DATABASE("database", "数据库", "关系型数据库连接", "database-icon"),
    EXCEL("excel", "Excel文件", "Excel文件数据源", "excel-icon"),
    KAFKA("kafka", "Kafka", "分布式流处理平台", "kafka-icon"),
    FTP("ftp", "FTP/SFTP", "文件传输协议", "ftp-icon");

    // 枚举属性对应数据库字段
    private final String code;  // 使用code作为主键
    private final String name;
    private final String description;
    
    private final String icon;

    SourceType(String code, String name, String description, String icon) {
        this.code = code;
        this.name = name;
        this.description = description;
        this.icon = icon;
    }

    // 根据code获取枚举
    public static Optional<SourceType> fromCode(String code) {
        return Arrays.stream(values())
            .filter(type -> type.getCode().equalsIgnoreCase(code))
            .findFirst();
    }

    // Getter方法
    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getIcon() {
        return icon;
    }
}